//------------Sonic CD Spinning Top Script-------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

//-------Aliases-------//
#alias 50: TYPE_SPINNINGTOP
#alias Player.Value6:Player.MinRollSpeed


sub ObjectPlayerInteraction
	PlayerObjectCollision(C_BOX,-16,-8,16,24)
	TempValue1=Object.Value0
	if CheckResult==1
		if Player.State!=PlayerObject_SpinningTop
			Player.Speed=0
			Object.Value1=1
			Player.MinRollSpeed=4096
			if Player.XPos>Object.XPos
				Player.Timer=Player.XPos
				Player.Timer-=Object.XPos
				Object.Value0=128
			else
				Player.Timer=Object.XPos
				Player.Timer-=Player.XPos
				Object.Value0=384
			endif
		endif
		if Player.XPos>Object.XPos
			if Player.Left==1
				Player.Timer-=4096
			endif
			if Player.Right==1
				Player.Timer+=4096
			endif
		else
			if Player.Left==1
				Player.Timer+=4096
			endif
			if Player.Right==1
				Player.Timer-=4096
			endif
		endif
		Player.State=PlayerObject_SpinningTop
		Player.Animation=ANI_SPINNING_TOP
		Sin(Player.XPos,Object.Value0)
		Player.XPos*=Player.Timer
		Player.XPos>>=9
		Player.XPos+=Object.XPos
		TempValue0=Object.Value0
		TempValue0-=128
		TempValue0/=86
		Player.Frame=TempValue0
		Object.Value0+=16
		if Object.Value0>639
			Object.Value0-=512
		endif
		if Player.JumpPress==1
			CallFunction(PlayerObject_StartJump)
			Player.Speed=Player.XPos
			Player.Speed-=Object.XPos
			Player.Speed>>=2
			Player.State=PlayerObject_HandleAir
			Player.Timer=0
			PlayStageSfx(1,0)
		endif
	else
		if Object.Value1==1
			if Player.State==PlayerObject_SpinningTop
				if Player.Gravity==0
					Player.State=PlayerObject_HandleGround
					Object.Value1=0
					Player.Timer=0
				endif
			endif
		endif
	endif
endsub


sub ObjectDraw
	DrawSprite(Object.Frame)
	TempValue0=Ring.AniCount
	TempValue0&=1
	if TempValue0==0
		Object.Frame++
		if Object.Frame>2
			Object.Frame=0
		endif
	endif
endsub


sub ObjectStartup
	LoadSpriteSheet("R1/Objects.gif")
	SpriteFrame(-16,-8,32,16,101,76)
	SpriteFrame(-16,-8,32,16,101,76)
	SpriteFrame(-16,-8,32,16,134,76)
endsub

sub RSDK
	LoadSpriteSheet("Global/Display.gif")
	SetEditorIcon(Icon0,SingleIcon,-16,-16,32,32,1,143)
endsub
